import request from '/@/utils/request'
import type { Dict, DictQuery, DictForm, DictItem, DictItemQuery, DictItemForm } from '/@/types/dict'

// 获取字典列表
export function getDictList(params: DictQuery) {
  return request<{
    list: Dict[]
    total: number
  }>({
    url: '/admin/dict/getList',
    method: 'get',
    params
  })
}

// 添加字典
export function addDict(data: DictForm) {
  return request({
    url: '/admin/dict/doAdd',
    method: 'post',
    data
  })
}

// 编辑字典
export function editDict(dict_id: number, data: DictForm) {
  return request({
    url: '/admin/dict/doEdit',
    method: 'post',
    data: {
      dict_id,
      ...data
    }
  })
}

// 删除字典
export function deleteDict(dict_id: number) {
  return request({
    url: '/admin/dict/doDelete',
    method: 'post',
    data: { dict_id }
  })
}

// 获取字典项列表
export function getDictItemList(params: DictItemQuery) {
  return request<{
    list: DictItem[]
    total: number
  }>({
    url: '/admin/dictItem/getList',
    method: 'get',
    params
  })
}

// 添加字典项
export function addDictItem(data: DictItemForm) {
  return request({
    url: '/admin/dictItem/doAdd',
    method: 'post',
    data
  })
}

// 编辑字典项
export function editDictItem(item_id: number, data: DictItemForm) {
  return request({
    url: '/admin/dictItem/doEdit',
    method: 'post',
    data: {
      item_id,
      ...data
    }
  })
}

// 删除字典项
export function deleteDictItem(item_id: number) {
  return request({
    url: '/admin/dictItem/doDelete',
    method: 'post',
    data: { item_id }
  })
} 